from django.shortcuts import render
from rest_framework.viewsets import ModelViewSet  # 封装完成的ModelViewSet视图集
from studentweb.models import Faculty, Major, Student
from studentweb.serializer import FacultySerializer, MajorSerializer, StudentSerializer
from studentweb.filter import FacultyFilter, MajorFilter, StudentFilter  # 导入筛选类
from studentweb.paginations import MyPageNumberPaginations


class FacultyViewSet(ModelViewSet):
    """
    list: 获取所有学院名称
    create: 创建学院信息
    retrieve: 获取学院信息详情数据
    update: 完整更新学院信息
    partial_update: 部分更新学院信息
    destroy: 删除学院信息
    Args:
        ModelViewSet (_type_): _description_
    """
    queryset = Faculty.objects.all()
    serializer_class = FacultySerializer

    # 分页配置
    pagination_class = MyPageNumberPaginations

    # 设定筛选的后台
    filter_class = FacultyFilter


class MajorViewSet(ModelViewSet):
    """
    list: 获取所有专业名称
    create: 创建专业信息
    retrieve: 获取专业信息详情数据
    update: 完整更新专业信息
    partial_update: 部分更新专业信息
    destroy: 删除专业信息
    Args:
        ModelViewSet (_type_): _description_
    """
    queryset = Major.objects.all()
    serializer_class = MajorSerializer

    # 分页配置
    pagination_class = MyPageNumberPaginations

    # 设定筛选的后台
    filter_class = MajorFilter


class StudentViewSet(ModelViewSet):
    """
    list: 获取所有登录账号
    create: 创建学生信息
    retrieve: 获取学生信息详情数据
    update: 完整更新学生信息
    partial_update: 部分更新学生信息
    destroy: 删除学生信息
    Args:
        ModelViewSet (_type_): _description_
    """
    queryset = Student.objects.all()
    serializer_class = StudentSerializer

    # 分页配置
    pagination_class = MyPageNumberPaginations

    # 设定筛选的后台
    filter_class = StudentFilter

    # 指定查找匹配的字段
    search_fields = ('sno', 'name')
